﻿using CustomControls.Controls;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;

namespace CustomControls.Attached
{
    public class Utility
    {
        /// <summary>
        /// 刷新样式
        /// </summary>
        /// <param name="control"></param>
        public static void Refresh(FrameworkElement control)
        {
            if (control == null)
            {
                return;
            }
            //正在运行的状态
            if (!DesignerProperties.GetIsInDesignMode(control))
            {
                if (control.IsLoaded)
                {
                    SetColor(control);
                }
                else
                {
                    control.Loaded += delegate { SetColor(control); };
                }
            }
        }

        static void SetColor(FrameworkElement control)
        {
            //var mw = Window.GetWindow(control) is DMSkinWindow ? Window.GetWindow(control) as DMSkinWindow : null;
            //if (mw != null)
            //{
            //    if (control is ToggleButton) { (control as ToggleButton).Background = mw.BorderBrush; }
            //    if (control is DataGridRow) { (control as DataGridRow).BorderBrush = mw.BorderBrush; }
            //    if (control is AduDatePicker)
            //    {
            //        var dataPicker = (control as AduDatePicker);
            //        dataPicker.Foreground = mw.BorderBrush;
            //        dataPicker.BorderBrush = mw.BorderBrush;
            //    }
            //    if (control is AduTimeSelector) { (control as AduTimeSelector).Foreground = mw.BorderBrush; }
            //    if (control is AduTimeButton) { (control as AduTimeButton).Foreground = mw.BorderBrush; }
            //    if (control is AduCalendar) { (control as AduCalendar).Foreground = mw.BorderBrush; }
            //    if (control is AduCalendarItem) { (control as AduCalendarItem).Foreground = mw.BorderBrush; }
            //}
        }
    }
}
